package civicinity.ist.psu.edu.events;

import civicinity.ist.psu.edu.R;
import android.app.Activity;
import android.app.ActivityGroup;
import android.app.TabActivity;
import android.content.Context;
import android.content.Intent;
import android.content.res.Resources;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.TabHost;
import android.widget.TabHost.TabSpec;
import android.widget.TextView;

public class CivicinityEventSelected extends ActivityGroup{

	private TabHost mTabHost;
	
	/** Called when the activity is first created. */
	@Override
	public void onCreate(Bundle savedInstanceState) {
	    super.onCreate(savedInstanceState);
	    setContentView(R.layout.civicinity_event_selected);
	    
	    Intent gIntent = getIntent();
	    int eventID = gIntent.getExtras().getInt("event_id");
	    String eventTitle = gIntent.getExtras().getString("event_title");
	    String eventDescription = gIntent.getExtras().getString("event_description");
	    String eventURL = gIntent.getExtras().getString("event_feed_url");
	    boolean eventActive = gIntent.getExtras().getBoolean("event_active");
	    
	    Intent intentCal = new Intent(this, CivicinityCalFeed.class);
	    intentCal.putExtra("event_id", eventID);
	    intentCal.putExtra("event_title", eventTitle);
	    intentCal.putExtra("event_description", eventDescription);
	    intentCal.putExtra("event_feed_url", eventURL);
	    intentCal.putExtra("event_active", eventActive);
	    
	    Intent intentEvent = new Intent(this, CivicinityGallery.class);
	    intentEvent.putExtra("event_id", eventID);
	    intentEvent.putExtra("event_title", eventTitle);
	    intentEvent.putExtra("event_description", eventDescription);
	    
	    setupTabHost();
	    
	    mTabHost.getTabWidget().setDividerDrawable(R.drawable.tab_divider);
	    
	    setupTab(new TextView(this), "Schedule", intentCal);
	    setupTab(new TextView(this), "Photos", intentEvent);
	    
	    
	    
	    /*
	    tabHost.addTab(tabHost.newTabSpec("Calendar")
	    			.setIndicator("Event Info", res.getDrawable(android.R.drawable.ic_menu_my_calendar))
	    			.setContent(intentCal));
	    tabHost.addTab(tabHost.newTabSpec("Contests")
	    			.setIndicator("Event Contests", res.getDrawable(android.R.drawable.ic_menu_camera))
	    			.setContent(intentEvent));
	    */
	    
	    mTabHost.setCurrentTab(0);
	    // TODO Auto-generated method stub
	}
	
	private void setupTabHost() {
		mTabHost = (TabHost) findViewById(android.R.id.tabhost);
		mTabHost.setup(this.getLocalActivityManager());
	}
	
	private void setupTab(final View view, final String tag, Intent intent) {
		View tabview = createTabView(mTabHost.getContext(), tag);

		TabSpec setContent = mTabHost.newTabSpec(tag).setIndicator(tabview).setContent(intent);
		mTabHost.addTab(setContent);

	}

	private static View createTabView(final Context context, final String text) {
		View view = LayoutInflater.from(context).inflate(R.layout.tabs_bg, null);
		TextView tv = (TextView) view.findViewById(R.id.tabsText);
		tv.setText(text);
		return view;
	}
}